﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

//using Ivy.Common.Framework.GeneralUtility;
using Hsmp.SocietyAdmin.IBusinessLogic;
using Hsmp.SocietyAdmin.BusinessLogic;
using Hsmp.SocietyAdmin.Entity;
using HSMPWeb.ViewEntity;

namespace HSMPWeb.Pages
{
    public partial class SocietyListing : System.Web.UI.Page
    {
        #region  Variable & constant
        #endregion  Variable & constant

        #region Constructor & Destructor
        #endregion Constructor & Destructor

        #region Properties
        #endregion Properties

        #region Public Methods
        #endregion Public Methods

        #region Events
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadSocietylist();
            }
        }

        protected void btnRetrieveData_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Pages/SocietyDetails.aspx?SocietyId=" + this.TextBox1.Text);

        }
        #endregion Events

        #region Private Methods
        protected void LoadSocietylist()
        {
            try
            {
                List<Society> lSocietyList = new List<Society>();
                SocietyRegistrationBus lSocietyRegistrationBus = new SocietyRegistrationBus();
                lSocietyList = lSocietyRegistrationBus.GetAllSociety();

                //if (Session["lSociety"] == null)
                //{
                //    var vlstSociety = lSocietyRegistrationBus.GetAllSociety();
                //    lSociety = ((from x in vlstSociety select x).OrderByDescending(x => x.SocietyKey)).ToList();
                //    Session["lSociety"] = lSociety;
                //}
                //else
                //{
                //    lSociety = (List<Society>)Session["lSociety"];
                //}
                gdvSocietyList.DataSource = lSocietyList;
                gdvSocietyList.DataBind();

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print(ex.Message);
            }
        }

        protected void gdvSocietyList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

            try
            {
                List<Society> lSociety = new List<Society>();
                SocietyRegistrationBus lSocietyRegistrationBus = new SocietyRegistrationBus();

                lSocietyRegistrationBus.GetAllSociety();
                if (Session["lSociety"] == null)
                {
                    var vlstSociety = lSocietyRegistrationBus.GetAllSociety();
                    lSociety = ((from x in vlstSociety select x).OrderByDescending(x => x.SocietyKey)).ToList();
                    Session["lstSociety"] = lSociety;
                }
                else
                {
                    lSociety = (List<Society>)Session["lSociety"];
                }
                gdvSocietyList.DataSource = lSociety;
                gdvSocietyList.PageIndex = e.NewPageIndex;
                gdvSocietyList.DataBind();

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print(ex.Message);
            }
        }
        #endregion Private Methods

    }
}